<template>
  <navbar title="赛事详情" :isBack="true"></navbar>
  <loading v-if="!info"></loading>
  <matchDetail v-else :type="0" :info="info"></matchDetail>
</template>

<script setup lang="ts">
import { ref ,reactive} from 'vue'
import { onLoad ,onShareAppMessage, onShareTimeline} from '@dcloudio/uni-app'
import { getMatchDetail } from '@/service/api/index'
import matchDetail from '@/components/detail/match.vue'

let info = ref({
	isPoster:false
})
let fromId = reactive({
		id:0,
	})

onShareAppMessage((res: { from; target }) => {
  if (res.from === 'button') {
    // 来自页面内转发按钮
    console.log(res.target)
  }
  return {
    title: '闪击门球',
    path: 'pagesA/match/detail?id='+fromId.id,
	imageUrl: info.value.cover
  }
})


onShareTimeline(() => {
	return {
	    title: info.value.name,
	    path: 'pagesA/match/detail?id='+fromId.id,
		imageUrl: info.value.cover
	}
})

// 赛事详情
const getMatchDetailApi = async (id) => {
  fromId.id=id
  const { msg } = await getMatchDetail({ id })
  info.value = msg
	if(msg.achievement){
		info.value.tabsList=['详情', '赛程', '成绩']
	}else{
		info.value.tabsList=['详情', '赛程']
	}
	console.log(info);
  info.value.loaction = {
    scale: 18,
    name: info.value.name,
    latitude: Number(info.value.latitude),
    longitude: Number(info.value.longitude),
    address: info.value.province + info.value.city + info.value.address
  }
}

onLoad((option) => {
  if (option.scene) return getMatchDetailApi(decodeURIComponent(option.scene))
  // 赛事详情
  getMatchDetailApi(option.id)
})
</script>

<style lang="scss" scoped></style>
